<?php
	// On prolonge la session
	session_start();
	$id_anim='';
	$code='';
	
	require_once dirname(__FILE__) . "/../../includes/config.php";
	require_once PHP_ROOTPATH.'/classes/database.php';
	
	//vérification des droits de l'utilisateur
		// On teste si la variable de session existe et contient une valeur
		if(empty($_SESSION['id_anim'])){
			// Si inexistante ou nulle, on redirige vers la page de saisie du code
			header('Location: ../recherche.php');
			exit();
		}
		else{
			$id_anim=$_SESSION['id_anim'];
			$code=$_SESSION['code'];
		}
	
?>

<!DOCTYPE html>
<html>
	<head>
        <meta charset="utf-8" />
        <link rel="stylesheet" href="../../style.css" />
		<!--[if lt IE 9]>
        <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
        <!--[if lte IE 7]>
        <link rel="stylesheet" href="../../style_ie.css" />
        <![endif]-->
        <title>Base de données microcèbes</title>
        
        <script type="text/javascript">
			function afficher(oSelect){
				var id=oSelect.id;
				var elt = document.getElementById(id);
				if(elt.style.display=="inline-block"){
					elt.style.display="none";
				}
				else{
					elt.style.display="inline-block";
				}
			}
		</script>
    </head>
    
    <body>
		<?php include((dirname(dirname(dirname(__FILE__))))."/menu.php"); ?>
		<?php include((dirname(dirname(__FILE__)))."/calcul_age.php"); ?>
		<section id="main">
			<header>
				<h1>Recherche - Test d'induction animal <?php echo $code;?></h1>
			</header>

			<?php include((dirname(dirname(__FILE__)))."/menu_recherche.php"); ?>
			<section id="animal">
								
				<section id="contenu">
				<?php 								 
					$idconnect=Database::getInstance();
					$query=pg_query($idconnect,"SELECT test_induction.id_res,date_test,experimentateur,produit_injecte,qte_injectee,localisation,resultat
					FROM test_induction,resultat_test,test,type_test 
					WHERE label LIKE '%Test induction%' AND id_animal='$id_anim'
					AND test_induction.id_res=resultat_test.id_res
					AND resultat_test.id_test=test.id_test AND test.id_type_test=type_test.id_type_test");
					$int = pg_num_rows($query);
					if($int==0){echo("<p><label>Pas d'informations disponibles</label></p>");}
					else{
						//informations induction
						$i=0;
						while ($back = pg_fetch_assoc($query)) {		
							if($back["date_test"]){
								echo "<div><label class=\"titre2\">Induction du ".date("d/m/Y", strtotime($back["date_test"]))."</label><input type=\"button\" onclick=\"afficher(induc".$i.")\" value=\"Détail\"></div>";
								echo "<section class=\"autre\" id=\"induc".$i."\"><p>";
								echo "<label><strong>Age (mois): </strong>".calcul_age($_SESSION['date_n'],$back["date_test"])."</label><br/>";
								echo "<label><strong>Age (cycle): </strong>".calcul_age($_SESSION['date_n'],$back["date_test"])/8;	
								echo "</label><br/>";
							}
							if($back["experimentateur"]){echo "<label><strong>Expérimentateur: </strong>".$back["experimentateur"]."</label><br/>";}
							if($back["produit_injecte"]){echo "<label><strong>Produit injecté: </strong>".$back["produit_injecte"]."</label><br/>";}		
							if($back["qte_injectee"]){echo "<label><strong>Quantité injectée: </strong>".$back["qte_injectee"]."</label><br/>";}	
							if($back["localisation"]){echo "<label><strong>Localisation de l'injection: </strong>".$back["localisation"]."</label><br/>";}	
							if($back["resultat"]){echo "<label><strong>Résultat: </strong>".$back["resultat"]."</label><br/>";}	
							echo "</p>";
							
							//récupération des photos
							$query3=pg_query($idconnect,"SELECT * from photo_induction where id_res=".$back["id_res"]);
							echo "<div><label class=\"titre2\">Photos de l'induction</label><input type=\"button\" onclick=\"afficher(photo_induc".$i.")\" value=\"Détail\"></div>";
							echo "<p class=\"autre\" id=\"photo_induc".$i."\">";
							$int3 = pg_num_rows($query3);
							if($int3==0){echo("<label>Pas de photographies</label>");}
							else{
								while ($back3 = pg_fetch_assoc($query3)) {
									if($back3["photo"]){
										$date=date("d.m.Y", strtotime($back["date_test"]));
										echo "<img src=\"../../photos_induction/$date/$id_anim/".$back3['photo']."\"  height=\"40%\" width=\"40%\" 
										alt=\"image ".$back3['photo']." introuvable\"/><br/>";
									}
								}
							}
							echo "</p></section>";
							$i++;			
						}
					} 
				?>
				
			</section>
			
		</section>
	</body>
</html>
